package hjslm.Controller.Front;

import java.util.ArrayList;
import java.util.List;

import hjslm.Bean.NavcustomBean;
import hjslm.Bean.PictureBean;
import hjslm.Bean.TeacherBean;
import hjslm.Service.IBaseTwoService;
import hjslm.Service.INavCustomService;
import hjslm.Service.IPictureService;
import hjslm.Service.ITeacherService;
import hjslm.Service.IWeixinService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import hjslm.Bean.BaseTwoBean;
import framework.base.common.Pager;
import framework.base.controller.BaseController;

@Controller
@RequestMapping("/teacher")
public class FTeacherController extends BaseController{

	/**
	 * 教师控制层
	 */
	private static final long serialVersionUID = 1L;
	
	@Autowired
	ITeacherService teacherService;
	
	@Autowired
	IWeixinService weixinService;
	
	@Autowired
	IBaseTwoService baseTwoService;
	
	@Autowired
	IPictureService pictureService;
	
	@Autowired
	INavCustomService navCustomService;

	@Override
	public void setLogger() {		
	}
	
	@RequestMapping("/index")
	public ModelAndView index(TeacherBean bean,Pager<TeacherBean> pager,String top){
		ModelAndView modelAndView = new ModelAndView("front/teacher/index");
		pager.setCountPerPage(10);
		modelAndView.addObject("bean", bean);
		
		pager = teacherService.selectPageLike(bean, pager);
		modelAndView.addObject("pager", pager);
		
		//基本信息
		List<BaseTwoBean> listbt = baseTwoService.selectList(null);
		List<BaseTwoBean> listGrade = new ArrayList<BaseTwoBean>();
		List<BaseTwoBean> listSubject = new ArrayList<BaseTwoBean>();
		List<BaseTwoBean> listQuyu= new ArrayList<BaseTwoBean>();
		for (BaseTwoBean baseTwoBean : listbt) {
			switch (baseTwoBean.getBotype()) {
			case "年级":
				listGrade.add(baseTwoBean);
				break;
			case "科目":
				listSubject.add(baseTwoBean);
				break;
			case "地址":
				listQuyu.add(baseTwoBean);
				break;
			}
		}
		modelAndView.addObject("listGrade", listGrade);
		modelAndView.addObject("listSubject", listSubject);
		modelAndView.addObject("listQuyu", listQuyu);
		
		List<NavcustomBean> navList  = navCustomService.selectList(null);
		modelAndView.addObject("navList", navList);
		modelAndView.addObject("map", weixinService.selectMap());
 		return modelAndView;
	}
	
	@RequestMapping("/info")
	public ModelAndView info(TeacherBean bean){
		ModelAndView modelAndView = new ModelAndView("front/teacher/info");
		bean = teacherService.selectOne(bean);
		modelAndView.addObject("bean", bean);
		PictureBean pictureBean = new PictureBean();
		pictureBean.setTeaid(bean.getId());
		List<PictureBean> list = pictureService.selectList(pictureBean);
		modelAndView.addObject("list", list);
		
		List<NavcustomBean> navList  = navCustomService.selectList(null);
		modelAndView.addObject("navList", navList);
		
		modelAndView.addObject("map", weixinService.selectMap());
		return modelAndView;
	}
	
	@RequestMapping("/video")
	public ModelAndView vedio(String vid) {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("front/teacher/video");
		modelAndView.addObject("vid", vid);
		return modelAndView;
	}

}
